class SyncLoopHook { // 钩子 是同步的

  constructor(args) { // args => ['name']
    this.tasks = [];

  }

  tap(name, task) {// 事件名字 事件方法
    this.tasks.push(task);
  }

  call(...args) {
    this.tasks.forEach(task => {
      let ret;
      do {
        ret = task(...args);
      } while (ret !== undefined);
    });
  }

}

let hook = new SyncLoopHook(['name']);
let total = 0;
hook.tap('react', (name) => {
  console.log('react', name);
  return ++total === 3 ? undefined : '继续学习 react';
});

hook.tap('vue', (name) => {
  console.log('vue', name);
});

hook.tap('angular', (name) => {
  console.log('angular', name);
});

hook.call('gzw');
